package com.xiangqian.strategy;

import com.xiangqian.service.PayType;
import com.xiangqian.serviceimpl.Alipay;
import com.xiangqian.serviceimpl.BalancePay;
import com.xiangqian.serviceimpl.WeChatPay;

/**
 * 支付策略
 */
public class PayTypeStarategy {

    private PayType payType;

    /**
     * 通过构造方法初始支付类型
     *
     * @param type 支付类型
     */
    public PayTypeStarategy(String type) {
        switch (type) {
            case "alipay":
                payType = new Alipay();
                break;
            case "balancePay":
                payType = new BalancePay();
                break;
            case "weChatPay":
                payType = new WeChatPay();
                break;
            default:
                throw new IllegalArgumentException("Invalid payType type: " + type);
        }
    }

    /**
     * 调用支付方法
     */
    public void pay() {
        payType.pay();
    }
}
